import java.util.Arrays;

public class MyArrayList {
  public int[] myArrayList;
  public int usedSize;
  public MyArrayList(){
      myArrayList=new int[10];
      int usedSize=0;
  }
  public void add(int val){
      if(isFull()){
          myArrayList= Arrays.copyOf(myArrayList,myArrayList.length*2);
      }
      myArrayList[usedSize]=val;
      usedSize++;


  }
  public void add(int pos,int value){
      if(pos<0||pos>usedSize){
          throw new ArrayPosException("pos位置为："+pos);
      }
      if(isFull()){
          myArrayList= Arrays.copyOf(myArrayList,myArrayList.length*2);
      }
      for (int i = usedSize-1; i <=pos ; i++) {
          myArrayList[i+1]=myArrayList[i];
      }
      myArrayList[pos]=value;
      usedSize++;
  }
  public boolean isFull(){
     return this.usedSize==myArrayList.length;
  }
  //返回下标
  public int toFind(int key){
      for (int i = 0; i < usedSize; i++) {
          if(key==myArrayList[i]){
              return i;
          }
      }
      return -1;
  }
  public boolean find(int key){
      for (int i = 0; i < usedSize; i++) {
          if(key==myArrayList[i]){
              return true;
          }
      }
      return false;
  }
  public void remove(int pos){
      if(pos<0||pos>=usedSize){
          throw new ArrayPosException("pos位置为："+pos);
      }
      for (int i =pos; i < usedSize-1; i++) {
          myArrayList[i]=myArrayList[i+1];
      }
      usedSize--;
  }
  public void setValue(int pos,int val){
      if(pos<0||pos>=usedSize){
          throw new ArrayPosException("pos位置为："+pos);
      }
      myArrayList[pos]=val;

  }
  public void display(){
      for (int i = 0; i < usedSize; i++) {
          System.out.println(myArrayList[i]);
      }
  }
}
